package com.example.demo.pojo;

public class ResBuilder {

    public static <T> Res getSuccess() {
        CodeEnum success = CodeEnum.SUCCESS;
        return create(null, success.getCode(), success.getMessage(), null);
    }

    public static <T> Res getSuccess(T data) {
        CodeEnum success = CodeEnum.SUCCESS;
        return create(data, success.getCode(), success.getMessage(), null);
    }

    public static <T> Res getError(CodeEnum codeEnum, String tipsMsg) {
        return create(null, codeEnum.getCode(), codeEnum.getMessage(), tipsMsg);
    }

    public static <T> Res getError(int code, String msg) {
        return create(null, code, msg, null);
    }

    public static <T> Res getError(String msg, String tipsMsg) {
        return create(null, CodeEnum.PARAMETER_ERROR.getCode(), msg, tipsMsg);
    }

    private static <T> Res create(T data, int code, String msg, String tipsMsg) {
        Res result = new Res();
        result.setData(data);
        result.setCode(code);
        result.setMsg(msg);
        result.setTipsMsg(tipsMsg);
        return result;
    }
}
